//
//  Http.m
//  thefirst
//
//  Created by Apple on 16/5/17.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "Http.h"


@implementation Http

+ (AFHTTPSessionManager *)HttpManager
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",  nil];
    manager.requestSerializer.timeoutInterval = 15.f;
    return  manager;
}


+ (void)getWithUrl:(NSString *)url
                          params:(NSDictionary *)params
                         success:(CLResponseSuccess)success
                            fail:(CLResponseFail)fail
{
    AFHTTPSessionManager *manager = [self HttpManager];

    [manager GET: [NSString stringWithFormat:@"%@%@",kBasicsURL,url] parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        !success ?:success(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        !fail ?: fail(error);
    }];

}


+ (void)postWithUrl:(NSString *)url
                           params:(NSDictionary *)params
                          success:(CLResponseSuccess)success
                             fail:(CLResponseFail)fail
{
    AFHTTPSessionManager *manager = [self HttpManager];
    [manager POST: [NSString stringWithFormat:@"%@%@",kBasicsURL,url] parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
         !success ?:success(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        !fail ?: fail(error);
    }];
}






@end
